//
//  LGNavigationController.m
//  LuxuryGoods
//
//  Created by 刘星辰 on 2018/5/19.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "LGNavigationController.h"
#import "UIViewController+NavRegister.h"

@interface LGNavigationController ()<UIGestureRecognizerDelegate, UINavigationControllerDelegate>

@end

@implementation LGNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    
    self.interactivePopGestureRecognizer.enabled = YES;
    __weak typeof (self) weakSelf = self;
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        self.interactivePopGestureRecognizer.delegate = weakSelf;
    }
//    self.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:TITLE_FONT_19,NSFontAttributeName,
//                                              BLACK_COLOR,NSForegroundColorAttributeName, nil];
    //    [self.navigationBar setBarTintColor:WHITE_COLOR];
    //    [self.navigationBar setTintColor:WHITE_COLOR];
    self.navigationBar.translucent = NO;
}

//用于单独修改某个视图控制器状态栏的颜色
-(UIViewController *)childViewControllerForStatusBarStyle{
    //    if ([self.topViewController isKindOfClass:NSClassFromString(@"NDPatientCenterViewController")]) {
    //        return self.topViewController;
    //    }
    //    return nil;
    
    if (self.topViewController.transformStatusBarStyle == YES)
    {
        return self.topViewController;
    }
    return nil;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    // fix 'nested pop animation can result in corrupted navigation bar'
    if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        //        self.interactivePopGestureRecognizer.enabled = NO;
    }
    
    if (self.viewControllers.count == 1)
    {
        viewController.hidesBottomBarWhenPushed = YES; //viewController是将要被push的控制器
    }
    [super pushViewController:viewController animated:animated];
}

- (void)navigationController:(UINavigationController *)navigationController
       didShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated
{
    if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        navigationController.interactivePopGestureRecognizer.enabled = YES;
    }

}

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
 
    if (viewController.hiddenNavigationBar == YES)
    {
        [self setNavigationBarHidden:YES animated:YES];
    }
    else
    {
        [self setNavigationBarHidden:NO animated:YES];
    }
}

//支持的方向
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeRight;
}

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
    NSLog(@"%@ - %@",NSStringFromSelector(_cmd),[self class]);
}

@end
